<template>
  <div class="card-grid">
    <div class="welcome-tips" v-show="info.isWelcome">欢迎来到这个页面</div>
    <div class="loading-tips" v-show="info.isLoading">加载中</div>
    <div class="error-tips" v-show="info.errorMessage">
      错误消息：{{ info.errorMessage }}
    </div>

    <div class="card-info" v-for="u in info.userList" :key="u.login">
      <a :href="u.html_url" target="_blank" rel="noopener noreferrer">
        <img :src="u.avatar_url" :alt="u.login" />
        <div class="card-body">
          <h3>{{ u.login }}</h3>
        </div>
      </a>
    </div>
  </div>
</template>

<script>
export default {
  data: function () {
    return {
      info: {
        userList: [],
        isWelcome: true,
        isLoading: false,
        errorMessage: "",
      },
    };
  },
  mounted() {
    this.$bus.$on("getGithubUsers", (obj) => {
      this.info = { ...this.info, ...obj };
    });
  },
  beforeDestroy() {
    this.$bus.$off("getGithubUsers");
  },
};
</script>

<style scoped>
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 24px;
  padding: 20px;
  max-width: 1200px;
  margin: 0 auto;
}

.welcome-tips {
  grid-column: 1 / -1;
  text-align: center;
  font-size: 28px;
  font-weight: bold;
  color: #2c3e50;
  margin: 20px 0;
  padding: 20px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  border-radius: 12px;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
}

.loading-tips {
  grid-column: 1 / -1;
  text-align: center;
  font-size: 18px;
  color: #7f8c8d;
  padding: 15px;
  background-color: #f8f9fa;
  border-radius: 8px;
  border-left: 4px solid #3498db;
}

.error-tips {
  grid-column: 1 / -1;
  text-align: center;
  font-size: 16px;
  color: #e74c3c;
  padding: 15px;
  background-color: #fdf2f2;
  border-radius: 8px;
  border: 1px solid #f5c6cb;
}

.card-info {
  background: white;
  border-radius: 12px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
  transition: all 0.3s ease;
  overflow: hidden;
}

.card-info:hover {
  transform: translateY(-5px);
  box-shadow: 0 8px 25px rgba(0, 0, 0, 0.15);
}

.card-info a {
  text-decoration: none;
  color: inherit;
  display: block;
  height: 100%;
}

.card-info img {
  width: 100%;
  height: 180px;
  object-fit: cover;
  border-bottom: 1px solid #eee;
}

.card-body {
  padding: 16px;
}

.card-body h3 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
  color: #2c3e50;
  text-align: center;
}

@media (max-width: 768px) {
  .card-grid {
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 16px;
    padding: 16px;
  }

  .welcome-tips {
    font-size: 22px;
    margin: 10px 0;
    padding: 15px;
  }
}
</style>